#include <stdio.h>
#include <stdlib.h>

typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode {
  ElementType Data;
  BinTree Left;
  BinTree Right;
};

BinTree CreatBinTree();
void InorderTraversal(BinTree BT);
void PreorderTraversal(BinTree BT);
void PostorderTraversal(BinTree BT);
void LevelorderTraversal(BinTree BT);

int main() {
  BinTree BT = CreatBinTree();
  printf("Inorder:");
  InorderTraversal(BT);
  printf("\n");
  printf("Preorder:");
  PreorderTraversal(BT);
  printf("\n");
  printf("Postorder:");
  PostorderTraversal(BT);
  printf("\n");
  printf("Levelorder:");
  LevelorderTraversal(BT);
  printf("\n");
  return 0;
}
/* 你的代码将被嵌在这里 */
void displayNode(BinTree node) {
  printf(" %c", node->Data);
  return;
}

void PreorderTraversal(BinTree BT) {
  if (BT == NULL) {
    return;
  }
  displayNode(BT);
  PreorderTraversal(BT->Left);
  PreorderTraversal(BT->Right);
}

void InorderTraversal(BinTree BT) {
  if (BT == NULL) {
    return;
  }
  InorderTraversal(BT->Left);
  displayNode(BT);
  InorderTraversal(BT->Right);
}

void PostorderTraversal(BinTree BT) {
  if (BT == NULL) {
    return;
  }
  PostorderTraversal(BT->Left);
  PostorderTraversal(BT->Right);
  displayNode(BT);
}
void LevelorderTraversal(BinTree BT) {
  if (!BT) {
    return;
  }

  BinTree b[30];
  int front = 0;
  int tail = 0;

  BinTree temp = NULL;
  b[tail++] = BT;

  while (front < tail) {
    temp = b[front++];
    displayNode(temp);
    if (temp->Left) {
      b[tail++] = temp->Left;
    }
    if (temp->Right) {
      b[tail++] = temp->Right;
    }
  }
}
